#include"PageLib.h"
#include"rss.h"
#include<map>
#include<fstream>
using std::map;
using std::pair;
using std::ofstream;
PageLib::PageLib(){}
void PageLib::create(){
    DIR * pdir=opendir("/home/zzh/cpp/project/v1_project/yuliao/renmingyuliao");
     if (pdir == NULL) {
        perror("opendir");
        return;
    }
    struct dirent* pdirent;
    int idx=0;
    size_t off=0;
    map<int,pair<int,int>> offlib;
    while((pdirent=readdir(pdir))){
        if(string(pdirent->d_name)!="."&&string(pdirent->d_name)!=".."){
            RSS rss(20);
            string path="/home/zzh/cpp/project/v1_project/yuliao/renmingyuliao/"+string(pdirent->d_name);
            cout<<path<<"\n";
            rss.read(path);
            rss.store("/home/zzh/cpp/project/v1_project/search/data/pagelib.dat",idx,off,offlib);
        }
    }
    closedir(pdir);
    ofstream ofs("/home/zzh/cpp/project/v1_project/search/data/offset.dat");
    for(auto ele:offlib){
        ofs<<ele.first<<" "<<ele.second.first<<" "<<ele.second.second<<"\n";
    }
    
}